<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80"
      @submit="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }"
      @reset="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="平台名称" name="name">
            <t-input v-model="queryParams.name" clearable placeholder="请输入平台名称" style="width: 240px" />
          </t-form-item>
          <!-- <t-form-item label="平台类别" name="platformCategory">
            <t-select style="width: 240px" clearable v-model="queryParams.platformCategory"
              :options="dict.type.platform_category">
            </t-select>
          </t-form-item>

          <t-form-item label="平台状态" name="platformStatus">
            <t-select style="width: 240px" clearable v-model="queryParams.platformStatus"
              :options="dict.type.platform_status">
            </t-select>
          </t-form-item> -->
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="base" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- <div class="btn-group-inline">
      <t-button @click="apply" variant="outline" theme="primary">
        <t-icon name="add" slot="icon"/>
        录入
      </t-button>
    </div> -->
    <t-table rowKey="index" size="small" :data="data" :columns="columns" hover :pagination="pagination"
      :loading="dataLoading" :sort="sort" :hideSortTips="true" @sort-change="sortChange">
      <template #name="{ row }">
        <t-link @click="dialog.objId = row.id; dialog.header = row.name; dialog.open_project_detail = true"
          hover="color" theme="primary">{{ row.name }}</t-link>
      </template>
      <template #platformCategory="{ row }">
        {{ row.platformCategory | filterByDict(dict.type.platform_category) }}
      </template>
      <template #technicalField="{ row }">
        {{ row.technicalField | filterByDict(dict.type.platform_technical_field) }}
      </template>
      <template #constructionMode="{ row }">
        {{ row.constructionMode | filterByDict(dict.type.construction_mode) }}
      </template>
      <template #declarationMethod="{ row }">
        {{ row.declarationMethod | filterByDict(dict.type.declaration_method) }}
      </template>


      <template #platformStatus="{ row }">
        <t-tag @click="dialog.header = row.name; dialog.objId = row.id; dialog.open_approve_list = true;"
          class="cursor-pointer" :theme="handleTheme(row.platformStatus, dict.type.approve_status)" variant="light">
          {{ row.platformStatus | filterByDict(dict.type.approve_status) }}
        </t-tag>
      </template>



      <template #score="{ row }">
        <t-link @click="scoreAction(row.id, row.name)" hover="color" theme="primary">{{ row.score }}</t-link>
      </template>
      <template #grade="{ row }">
        <t-tag class="cursor-pointer" :theme="handleTheme(row.grade, dict.type.kjpt_grade)" variant="light">
          {{ row.grade | filterByDict(dict.type.kjpt_grade) }}
        </t-tag>
      </template>
      <template #op="{ row }">

        <t-button @click="edit(row)" size="small" variant="text" class="t-button-link"
          v-if="$store.state.user.roles.includes('admin')">
          <t-icon name="edit-1" slot="icon" />
          编辑
        </t-button>
        <t-button size="small"
          @click="dialog.objId = row.id; dialog.header = row.name; dialog.open_project_detail = true" variant="text"
          class="t-button-link">
          <t-icon name="info-circle" slot="icon" />
          详情
        </t-button>

      </template>

    </t-table>

    <platform-my-detail-dialog :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_project_detail"
      v-if="dialog.open_project_detail"></platform-my-detail-dialog>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list"
      v-if="dialog.open_approve_list"></approve-list>
  </div>
</template>

<script>
import ApproveList from './components/approve-list.vue';
import PlatformMyDetailDialog from "./components/platform-my-detail-dialog.vue";

export default {
  name: "platform-index",
  dicts: ["platform_category", "platform_status", 'platform_technical_field', 'construction_mode', 'declaration_method', 'approve_status', 'kjpt_grade'],
  components: {
    PlatformMyDetailDialog,
    ApproveList
    // PlatformDetailDialog,
    // PlatformScoreList
  },
  data () {
    return {
      sort: [],
      dialog: {
        open_project_detail: false,
        open_approve_list: false,
        header: "",
        objId: 0,
        open_list: false
      },
      dictTypes: {},
      projectCategoryOptions: [],
      columns: [
        {
          colKey: "name",
          title: "平台名称",
          align: "center",
          width: 220

        },
        {
          colKey: "platformCategory",
          title: "平台类型",
          align: "center",
          width: 160,
        },
        {
          colKey: "technicalField",
          title: "技术领域",
          align: "center",
          width: 160,
        },
        {
          colKey: "constructionMode",
          title: "组建方式",
          align: "center",
          width: 160,
        },
        {
          colKey: "declarationMethod",
          title: "申报方式",
          align: "center",
          width: 160,
        },
        {
          colKey: "declarationDate",
          title: "申报日期",
          align: "center",
          width: 160,
        },
        {
          colKey: "platformStatus",
          title: "平台状态",
          align: "center",
          width: 100,
          fixed: 'right'
        },
        {
          colKey: "score",
          title: "积分",
          align: "center",
          width: 80,
          fixed: 'right'
        },
        {
          colKey: "grade",
          title: "积分结果",
          align: "center",
          width: 80,
          fixed: 'right'
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 220,
          fixed: 'right'
        },
      ],
      data: [
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: "",
        platformCategory: "",
        // platformStatus: '',
        // unitName: ""
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  async created () {
    Object.assign(this.queryParams, this.handelQuery(this.queryParams, this.$route.query))
    this.getList();
  },
  methods: {
    // apply() {
    //   this.$router.push(`/kjpt/other/platform/platform-apply/${Date.parse(new Date())}`);
    // },
    scoreAction (idStr, name) {
      this.$router.push({ path: `/kjpt/other/platform/platform-score-list/${idStr}`, query: { title: name + '-积分管理' } });
    },
    // 编辑按钮
    edit (row) {
      this.$router.push({ path: `/kjpt/other/platform/platform-apply/${row.id}`, query: { title: "平台编辑" } });
    },
    createPDF (row) {
      const instance = this.$loading({
        fullscreen: true,
        attach: 'body',
        preventScrollThrough: false,
      });
      this.$api.kjxm.project.projectPDF(row.id).then(response => {
        window.open(response.data.fullFilePath, '_blank')
        instance.hide();
      }).catch((e) => {
        instance.hide();
        this.$message.error(e.toString());
      });
    },
    sortChange (sort) {
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if (sort instanceof Array) {
        orderByColumn = sort.map(val => val.sortBy)
        isAsc = sort.map(val => val.descending ? `desc` : `asc`)
      } else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending ? `desc` : `asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    getList () {
      this.dataLoading = true;
      this.queryParams.pageNum = this.pagination.current || 1;
      this.$api.kjpt.project.list(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },

  }
}
</script>

<style scoped></style>
